package com.hejia.alauda.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.hejia.alauda.entity.example.B2BPayOrderExample;
import com.hejia.alauda.utils.Pager;

import org.springframework.stereotype.Service;

import com.hejia.alauda.entity.B2BPayOrder;
import com.hejia.alauda.persistence.mybatis.B2BPayOrderMapper;

/**
 * 
 * 
 *
 *
 * Created by showone on 2015 上午10:31:29.
 *
 * @Copyright: 2015 www.hejiajinrong.com All rights reserved.
 */
@Service
public class B2BPayOrderServiceImpl implements B2BPayOrderService {

	@Resource
	private B2BPayOrderMapper mapper;

	/**
	 * 增加企业充值订单
	 * 
	 * @param order
	 * @return
	 */
	public boolean addB2BPayOrder(B2BPayOrder order) {
		order.setCreateDate(new Date());
		order.setModifyDate(new Date());
		return mapper.insert(order) > 0;
	}

	public boolean updateOrderStatusByOrderNumber(String orderNumber,
			B2BPayOrder.Status status) {
		return mapper.updateOrderStatusByOrderNumber(orderNumber, status) > 0;
	}

    @Override
    public Pager<B2BPayOrder> pagerB2bPayOrder(B2BPayOrder.Status status, String valueDate, Pager<B2BPayOrder> pager) {
        B2BPayOrderExample example = new B2BPayOrderExample();
        if (valueDate != null) {
//            example.appendCriterion("status=", status);
            example.appendCriterion("str_to_date(createDate,'%Y-%m-%d')=", valueDate);
        }
        example.setOrderByClause("createDate desc");
        List<B2BPayOrder> list = mapper.selectByExample(example, pager);
        int count = mapper.countByExample(example);
        pager.setList(list);
        pager.setTotalCount(count);
        return pager;
    }

	@Override
	public B2BPayOrder findB2BPayOrderByOrderNumber(String orderNumber) {
		B2BPayOrderExample example = new B2BPayOrderExample();
		example.appendCriterion("orderNumber =", orderNumber);
		return mapper.selectOneByExample(example);
	}
}
